namespace CSharpPro._0922;

public class Demo3
{
    //0929作业一输出1000以内的水仙花数
    public void TestPrint1()
    {
        Console.WriteLine("1000以内的水仙花数有：");
        
        for (int i = 100; i < 1000; i++)
        {
            int hundreds = i / 100;
            int tens = (i / 10) % 10;
            int units = i % 10;
            
            int sumOfCubes = (hundreds * hundreds * hundreds) +
                             (tens * tens * tens) +
                             (units * units * units);
            
            if (sumOfCubes == i)
            {
                Console.Write(i + " ");
            }
        }
    }

    //0929作业二输出100以内所有的质数
    public void TestPrint2()
    {
        Console.WriteLine("100以内的所有质数是：");

        for (int number = 2; number <= 100; number++)
        {
            bool isPrime = true;

            for (int divisor = 2; divisor <= Math.Sqrt(number); divisor++)
            {
                if (number % divisor == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                Console.Write(number + " ");
            }
        }
    }
}   